package com.shizhanzhe.gxb.my.activity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.widget.TextView;

import com.gyf.barlibrary.ImmersionBar;
import com.shizhanzhe.gxb.R;
import com.shizhanzhe.gxb.base.TabAdapter;
import com.shizhanzhe.gxb.my.fragment.IncomeFormFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import me.imid.swipebacklayout.lib.app.SwipeBackActivity;

/**
 * Created by YJ on 2019/1/8.
 */
public class IncomeFormActivity extends SwipeBackActivity {
    @BindView(R.id.top_title)
    TextView topTitle;

    public static String[] tabTitle = {"今日", "昨日", "本月", "上月"};
    public static String[] ids = {"1", "2", "3", "4"};
    @BindView(R.id.tablayout)
    TabLayout tablayout;
    @BindView(R.id.viewpager)
    ViewPager viewpager;
    @BindView(R.id.totalincome)
    TextView totalincome;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_income_form);
        ButterKnife.bind(this);
        ImmersionBar.with(this)
                .statusBarView(R.id.bar_0_view)
                .init();
        initData();
    }

    @OnClick(R.id.top_back)
    public void onViewClicked() {
        finish();
    }

    @SuppressLint("SetTextI18n")
    private void initData() {
        topTitle.setText("收入报表");
        totalincome.setText(getIntent().getStringExtra("totalincome")+"元");
        List<String> names = new ArrayList<>();
        for (int i = 0; i < tabTitle.length; i++) {
            names.add(tabTitle[i]);
        }
        List<Fragment> fragments = new ArrayList<>();
        for (int i = 0; i < ids.length; i++) {
            fragments.add(IncomeFormFragment.newInstance(ids[i]));
        }
        TabAdapter adapter = new TabAdapter(getSupportFragmentManager(), fragments, names);
        //给ViewPager设置适配器
        viewpager.setAdapter(adapter);
        //将TabLayout和ViewPager关联起来。
        tablayout.setupWithViewPager(viewpager);
        //设置可以滑动
        tablayout.setTabMode(TabLayout.MODE_FIXED);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ImmersionBar.with(this).destroy();
    }
}
